<template>
	<view>
		<view class="mainView">
			<image class="image" :src="src" mode="aspectFill"></image>
			<view class="ans">
				<view class="myCell" :wx:for="ans" wx:key="keyword">
					<myCell  bkColor="#dddddd" hoverColor="#bbbbbb" width="700rpx" load="1s" :label="item.keyword" :url="'/pages/search/search?value='+item.keyword" :src="serachSrc"></myCell>
				</view>
			</view>
		</view>
		<view class="safeView"></view>
	</view>
</template>

<script>
	export default{
		data(){
			return {
				src:'#',
				ans:[],
				serachSrc:this.myConfig.storageUrl+'/static/analysisSearch.png'
			}
		},
		onLoad(para){
			const that=this;
			if(para.hasOwnProperty('src')){
				that.src=para.src;
				const randomName=that.myConfig.getRandomFileName(para.src);
				wx.showLoading({
				  title:'loading...',
				  mask:true
				});
				wx.request({
					url:that.myConfig.hostUrl+'/api/checkScore.php',
					data:{
						openId:that.myConfig.openId
					},
					success:function(check){
						if(check.data.errCode==200){
							if(check.data.isEmpty==true){
								wx.showToast({
									title:'已经没有积分了哦',
									icon:'none',
									duration:1200
								});
								return ;
							}
							wx.cloud.uploadFile({
								cloudPath: 'tmp/'+randomName,
								filePath: para.src, 
								success:function(res){
									wx.request({
										url:'https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=Gv7ko7CTzK0hDfalz7p0ZKm2&client_secret=2kFoeSFhdXECt8IRxt62GWZ7qgMTCzSj&',
										method:'POST',
										success:function(ress){
											let access_token=ress.data.access_token;
											wx.request({
												url:'https://aip.baidubce.com/rest/2.0/image-classify/v2/advanced_general?access_token='+access_token,
												header:{
													'content-type':'application/x-www-form-urlencoded'
												},
												method:'POST',
												data:{
													url:that.myConfig.storageUrl+'/tmp/'+randomName
												},
												success:function(resss){
													console.log('AI',resss);
													wx.request({
														url:that.myConfig.hostUrl+'/api/costScore.php',
														method:'POST',
														data:{
															openId:that.myConfig.openId
														}
													});
													wx.hideLoading();
													if(resss.data.hasOwnProperty('result'))
														that.ans=resss.data.result;
													else{
														wx.showToast({
															title:'网络好像不太好',
															icon:'none',
															duration:1200
														});
													}
												},
												fail:function(){
													wx.hideLoading();
													wx.showToast({
														title:'网络好像不太好',
														icon:'none',
														duration:1200
													});
												}
											});
										}
									});
								}
							});
						}
					}
				});
			}
		},
		methods:{
			
		}
	}
</script>
<style scoped>
	.mainView{
		margin: 25rpx;
		text-align: center;
	}
	.image{
		width: 300rpx;
		height: 300rpx;
		border-radius: 50rpx;
		border: 1rpx solid #2C405A;
		box-shadow: 0 0 5rpx 0 #555555;
	}
	.myCell{
		margin-top: 30rpx;
		position: relative;
		animation: upMove 1.0s ease;
	}
</style>
